package com.example.stub;

import static java.lang.System.out;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class SimulatorThread extends Thread {

	private final static Logger log = LoggerFactory.getLogger(SimulatorThread.class);
			
	protected int no;
	
	protected int totalThread;
	
	protected abstract void execute() throws SimulatorException;
	
	public SimulatorThread(int no, int totalThread) throws Exception {
		this.no = no;
		this.totalThread = totalThread;
		preRun();
	}

	protected void preRun() throws Exception {}
	
	@Override
	public void run() {
		try {
			execute();
			out.println("processed " + no + "/" + totalThread);
		} catch (SimulatorException e) {
			out.println("failed to execute thread[" + e.getThreadNo() + "]");
			log.error("failed to execute thread[" + e.getThreadNo() + "]", e);
		}
	}
	
}
